<?php
/**
 *
 *
 * @author Zeon <scplay@gmail.com>
 * @date 2018/12/25 13:55
 * @copyright PanxSoft Inc.
 */
namespace Service\Model\Concerns;

use Illuminate\Database\Capsule\Manager;

class ManagerBootstrap
{
    /**
     * @var bool
     */
    private static $booted = false;

    /**
     * @link https://medium.com/@kshitij206/use-eloquent-without-laravel-7e1c73d79977 - 如何在 Laravel 之外的工程使用 Eloquent
     */
    static public function boot()
    {
        if (self::$booted) {
            return;
        }

        $manager = new Manager;

        $manager->addConnection([
            "driver"   => "mysql",
            "host"     => DB_HOSTNAME,
            "database" => DB_DATABASE,
            "username" => DB_USERNAME,
            "password" => DB_PASSWORD,
            "prefix"   => DB_PREFIX,
        ]);

        $manager->bootEloquent();

        self::$booted = true;
    }
}
